package com.siashan.toolkit.sms.core.entity;

/**
 * 短信频率限制
 *
 * @author siashan
 * @date 2023/5/17
 * @since 1.2.0
 */
public enum SmsFrequencyResult {
    /**
     * 白名单
     */
    IN_WHITELIST("白名单"),
    /**
     * 频率过高
     */
    FREQUENCY_TOO_HIGH("短信发送频率过高，请稍后重试"),


    /**
     * 超过每小时限额
     */
    OVER_HOUR_LIMIT("发送额度已用完，请一个小时后再试"),

    /**
     * 超过自然日限额
     */
    OVER_DAY_LIMIT("今日发送额度已用完，请明天再试"),

    /**
     * 可以发送
     */
    CAN_SEND("可以发送");

    private String desp;

    SmsFrequencyResult(String desp) {
        this.desp = desp;
    }


    public static SmsFrequencyResult parseLuaResult(String result) {

        if (result.equals("00")) {
            return SmsFrequencyResult.CAN_SEND;
        } else if (result.equals("01")) {
            return SmsFrequencyResult.FREQUENCY_TOO_HIGH;
        } else if (result.equals("02")) {
            return SmsFrequencyResult.OVER_HOUR_LIMIT;
        } else {
            return SmsFrequencyResult.OVER_DAY_LIMIT;
        }
    }

    public  boolean canSend(){
        return this.equals(IN_WHITELIST) ||this.equals(CAN_SEND);
    }


    public String getDesp() {
        return this.desp;
    }

    public void setDesp(String desp) {
        this.desp = desp;
    }
}
